<template>
  <div class="purchase-contanier" style="padding: 10px">
    <el-button type="primary" @click="addHandler">添加采购单</el-button>
    <el-tabs v-model="activeTab" type="border-card" style="margin-top: 10px" @tab-click="handleTabClick">
      <el-tab-pane label="全部" name="全部">
        <PurchaseTable v-if="activeTab==='全部'" :status="activeTab" />
      </el-tab-pane>
      <el-tab-pane label="待处理" name="待处理">
        <PurchaseTable v-if="activeTab==='待处理'" :status="activeTab" />
      </el-tab-pane>
      <el-tab-pane v-if="isAdmin" label="待分发" name="待分发">
        <PurchaseTable v-if="activeTab==='待分发'" :status="activeTab" />
      </el-tab-pane>
      <el-tab-pane v-if="isAdmin" label="已分发" name="已分发">
        <PurchaseTable v-if="activeTab==='已分发'" :status="activeTab" />
      </el-tab-pane>
      <el-tab-pane v-if="isBuyer" label="送审中" name="送审中">
        <PurchaseTable v-if="activeTab==='送审中'" :status="activeTab" />
      </el-tab-pane>
      <el-tab-pane label="已完成" name="已完成">
        <PurchaseTable v-if="activeTab==='已完成'" :status="activeTab" />
      </el-tab-pane>
    </el-tabs>
    <keep-alive>
      <PurchaseDialog
        :dialog-visible="dialogFormVisible"
        :dialog-title="dialogTitle"
        @closeDialog="closeHandler"
        @addDialog="addHandler"
        @getTable="handleTabClick"
      />
    </keep-alive>
  </div>
</template>

<script>
import PurchaseTable from './components/purchaseTable'
import PurchaseDialog from './components/purchaseDialog'
export default {
  name: 'Purchase',
  components: { PurchaseTable, PurchaseDialog },
  data() {
    return {
      isAdmin: false,
      isBuyer: false,
      activeTab: '全部',
      dialogFormVisible: false,
      dialogTitle: '添加采购单',
      name: '已分发'
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      if (this.$store.getters.roles.indexOf('admin') !== -1) {
        this.isAdmin = true
        this.isBuyer = false
      }
      if (this.$store.getters.roles.indexOf('buyer') !== -1) {
        this.isAdmin = false
        this.isBuyer = true
      }
    },
    handleTabClick(tab, event) {
      // this.$refs.child.getTable()
    },
    addHandler() {
      this.dialogFormVisible = true
    },
    closeHandler() {
      this.dialogFormVisible = false
    }
  }
}
</script>

<style lang="scss">

</style>
